import { defineStore } from "pinia";
import { ref } from "vue";
const useUserInfoStore = defineStore(
  "userInfo",
  () => {
    const info = ref({
      id: "",
      username: "",
    });

    const setInfo = (newInfo) => {
      info.value = newInfo;
    };

    const removeInfo = () => {
      info.value = {
        id: "",
        username: "",
      };
      // 清除localStorage中的持久化数据
      localStorage.removeItem("userInfo");
    };
    return {
      info,
      setInfo,
      removeInfo,
    };
  },
  {
    persist: {
      key: "userInfo",
      storage: localStorage,
      paths: ["info"],
    },
  }
);

export default useUserInfoStore;
